package com.zhs.gccs.activity.gccs;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.annimon.stream.Stream;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.hjq.shape.layout.ShapeLinearLayout;
//import com.wwren.picture.lib.PictureSelector;
//import com.wwren.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
import com.mapbox.geojson.Point;
import com.zhs.gccs.BuildConfig;
import com.zhs.gccs.R;
import com.zhs.gccs.adapter.GccsImageAdapter;
import com.zhs.gccs.base.BaseActivity;
import com.zhs.gccs.dao.TaskGccsFileDao;
import com.zhs.gccs.event.EventAddGccs;
import com.zhs.gccs.http.Api;
import com.zhs.gccs.http.ProgressObserver;
import com.zhs.gccs.model.GccsTaskData;
import com.zhs.gccs.model.GccsTaskFile;
import com.zhs.gccs.model.SensorData;
import com.zhs.gccs.model.WaterMaker;
import com.zhs.gccs.utils.DateUtils;
import com.zhs.gccs.utils.FileUtils;
import com.zhs.gccs.utils.GPSUtils;
import com.zhs.gccs.utils.OnNoDoubleClickListener;
import com.zhs.gccs.utils.SharedPrefHelper;
import com.zhs.gccs.utils.ToastUtils;
import com.zhs.gccs.utils.Utils;
import com.zhs.gccs.view.LocationAddress;
import com.zhs.gccs.vo.ApplyGccsTask;
import com.zhs.gccs.vo.BaseBean;
import com.zhs.gccs.vo.GccsStatistics;
import com.zhs.gccs.widget.LuckGlideEngine;
//import com.zhs.gccs.widget.selectImg.GlideEngine;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.hutool.core.util.IdUtil;

/**
 * Created by chengzf on 2024/7/20.
 */
public class GccsUserTaskDataDetailActivity extends BaseActivity {

    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.iv_bg)
    ImageView iv_bg;
    @BindView(R.id.iv_back)
    ImageView iv_back;
    @BindView(R.id.tv_task_time)
    TextView tv_task_time;
    @BindView(R.id.tv_task_gccs)
    TextView tv_task_gccs;
    @BindView(R.id.tv_task_adder)
    TextView tv_task_adder;
    @BindView(R.id.tv_task_result)
    TextView tv_task_result;
    @BindView(R.id.tv_task_remake)
    TextView tv_task_remake;
    @BindView(R.id.tv_task_type)
    TextView tv_task_type;
    @BindView(R.id.rv_images)
    RecyclerView rv_images;
    @BindView(R.id.ll_flag)
    ShapeLinearLayout ll_flag;
    @BindView(R.id.tv_edit)
    TextView tv_edit;

    private LocationAddress locationAddress;
    private LocationClient mBaiduLocationClient;
    private SensorData sensorData;
    private SensorManager sensorManager;
    SensorEventListener sensorEventListener;
    private TaskGccsFileDao taskGccsFileDao;
    private GccsImageAdapter mGccsImageAdapter;
    private ArrayList<GccsTaskFile> mImageList = new ArrayList<>();
    private String gccsTaskDataId;//当前数据id
    GccsTaskData gccsTaskData;//当前数据
    private int currentTaskFile;
    ApplyGccsTask taskBean;
    GccsStatistics gccsStatistics;
    private int request_code_edit = 100;

    private boolean addNewFiles = false;
    public static void start(Context context, String id, ApplyGccsTask taskBean, GccsStatistics gccsStatistics) {
        Intent intent = new Intent(context, GccsUserTaskDataDetailActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("task", taskBean);
        intent.putExtra("gccsStatistics", gccsStatistics);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_spot_check);
        ImmersionBar.with(this).transparentBar().statusBarDarkFont(false).init();
        ButterKnife.bind(this);
        llRoot.setPadding(0, ImmersionBar.getStatusBarHeight(this), 0, 0);
        taskBean = (ApplyGccsTask) getIntent().getSerializableExtra("task");
        gccsStatistics = (GccsStatistics) getIntent().getSerializableExtra("gccsStatistics");
        gccsTaskDataId = getIntent().getStringExtra("id");
        taskGccsFileDao = new TaskGccsFileDao();
        mGccsImageAdapter = new GccsImageAdapter();
        mGccsImageAdapter.setSelectedPosition(0);
        rv_images.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
        rv_images.setAdapter(mGccsImageAdapter);

        mGccsImageAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                if (mGccsImageAdapter.getData().get(i).isDefault()) {
                    XXPermissions.with(GccsUserTaskDataDetailActivity.this).permission(
                            Manifest.permission.MANAGE_EXTERNAL_STORAGE,
                            Manifest.permission.CAMERA
                    ).request(new OnPermissionCallback() {
                        @Override
                        public void onGranted(@NonNull List<String> list, boolean b) {
                            toTakePhoto();
                        }

                        @Override
                        public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {

                        }
                    });
                }else {
                    mGccsImageAdapter.setSelectedPosition(i);
                    mGccsImageAdapter.notifyDataSetChanged();
                    GccsTaskFile image = mGccsImageAdapter.getData().get(i);
//                Glide.with(GccsUserTaskDataDetailActivity.this).load(
//                        BuildConfig.BASEURL+"gccsFile/preview/image/"+image.getId()
//                                +"?token="+ SharedPrefHelper.getInstance().getToken()
//                ).into(iv_bg);
                    currentTaskFile = i-1;
                    if(TextUtils.isEmpty(image.getLocalUrl())){
                        String path = BuildConfig.BASEURL+"gccsFile/preview/image/"+image.getId()
                                +"?token="+ SharedPrefHelper.getInstance().getToken();
                        iv_bg.setTag(path);
                        Glide.with(context). load(path).into(iv_bg);
                    }else {
                        iv_bg.setTag(image.getLocalUrl());
                        Glide.with(context). load(image.getLocalUrl()).into(iv_bg);
                    }
                }
            }
        });
        initView();
        //定位初始化
        initBaiduLocation();
        //        initGdLocation();
        initSensor();
        getDataDetail();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        toFinish();
    }

    private void toFinish(){
        if(addNewFiles){
            EventBus.getDefault().post(new EventAddGccs());
        }
        finish();
    }

    private void initView() {
        iv_back.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                toFinish();
            }
        });
        iv_bg.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                List<GccsTaskFile> data = mGccsImageAdapter.getData();
                if(data!=null&&data!=null){
                    ArrayList<LocalMedia> selectList = new ArrayList<>();
                    for (int i = 0; i < data.size(); i++) {
                        GccsTaskFile imageBean = data.get(i);
                        if(!imageBean.isDefault()){
                            String url = imageBean.getLocalUrl();
                            if(TextUtils.isEmpty(imageBean.getLocalUrl())){
                                url = BuildConfig.BASEURL+"gccsFile/preview/image/"+imageBean.getId()
                                        +"?token="+ SharedPrefHelper.getInstance().getToken();
                            }
                            LocalMedia media = new LocalMedia();
                            media.setPath(url);
                            media.setRealPath(url);
                            media.setCutPath(url);
                            media.setCompressPath(url);
                            media.setOriginalPath(url);
                            media.setPosition(i);
                            selectList.add(media);
                        }
                    }
                    PictureSelector.create(context)
                            .openPreview()
//                            .setImageEngine(GlideEngine.createGlideEngine())
                            .setImageEngine(LuckGlideEngine.createGlideEngine())
                            .startActivityPreview(currentTaskFile, false, selectList);
//                    PictureSelector.create(GccsUserTaskDataDetailActivity.this)
//                            .themeStyle(R.style.picture_default_style) // xml设置主题
//                            .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)// 设置相册Activity方向，不设置默认使用系统
//                            .isNotPreviewDownload(false)// 预览图片长按是否可以下载
//                            .imageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
//                            .openExternalPreview(currentTaskFile, selectList);
                }
            }
        });

        tv_edit.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
//                GccsUserTaskDataFormActivity.start(context,
//                        taskBean, null, gccsStatistics,gccsTaskData);
                Intent intent = new Intent(context, GccsUserTaskDataFormActivity.class);
                intent.putExtra("task", taskBean);
//                intent.putExtra("path", null);
                intent.putExtra("gccsStatistics", gccsStatistics);
                intent.putExtra("gccsTaskData", gccsTaskData);
                startActivityForResult(intent,request_code_edit);
            }
        });
    }

    private void toTakePhoto() {
        PictureSelector.create(GccsUserTaskDataDetailActivity.this)
//                .openGallery(SelectMimeType.ofImage())
                .openCamera(SelectMimeType.ofImage())
//                .setImageEngine(LuckGlideEngine.createGlideEngine())
                .forResult(new OnResultCallbackListener<LocalMedia>() {
                    @Override
                    public void onResult(ArrayList<LocalMedia> result) {
                        for (int i1 = 0; i1 < result.size(); i1++) {
                            String path = result.get(i1).getRealPath();
                            writeImageWaterMarker(path);
                            GccsTaskFile gccsTaskFile = new GccsTaskFile();
                            gccsTaskFile.setLocalUrl(path);
//                            mImageList.add(new CommplaintBean(path, "", false));
                            mImageList.add(gccsTaskFile);
                        }
                        mGccsImageAdapter.setComplaintData(mImageList);
                        gccsTaskData.setFileList(mImageList);
                        saveGccsFileToLocal(gccsTaskData);
                        addNewFiles = true;
                    }

                    @Override
                    public void onCancel() {

                    }
                });
    }
    private void writeImageWaterMarker(String path) {
        try {
            File file = new File(path);
            FileInputStream fis = new FileInputStream(file);
            Bitmap bitmap = BitmapFactory.decodeStream(fis);
            List<WaterMaker> waterMakers = new ArrayList<>();
            DecimalFormat fmt = new DecimalFormat("##0.00000");
            String latlon = "";
            if(gccsTaskData!=null&&gccsTaskData.getLatitude()!=null
                    &&gccsTaskData.getLongitude()!=null){
                latlon = "N" + fmt.format(Double.parseDouble(gccsTaskData.getLatitude()))
                        + "E" + fmt.format(Double.parseDouble(gccsTaskData.getLongitude()));
            }
            String date = DateUtils.getDateTime();
            waterMakers.add(new WaterMaker("时间：", date));
            waterMakers.add(new WaterMaker("地点：", latlon));//parentActivity.getAddress()));
            waterMakers.add(new WaterMaker("采集人：", SharedPrefHelper.getInstance().getUserAccount()));
            waterMakers.add(new WaterMaker("项目：", taskBean.getPid()));
//            Bitmap textBitmap = BitmapUtil.createWatermark(context, bitmap, waterMakers);
            Bitmap textBitmap = Utils.saveWaterMask(context, 3, bitmap, date,
                    latlon,
                    gccsTaskData!=null?gccsTaskData.getAddress():"",
                    taskBean.getPid(),
                    SharedPrefHelper.getInstance().getUserAccount());
            FileUtils.saveBitmap(textBitmap, file.getCanonicalPath());
            Utils.writeLatLonIntoJpeg(file.getCanonicalPath(),
                    gccsTaskData!=null&&gccsTaskData.getLatitude()!=null?Double.parseDouble(gccsTaskData.getLatitude()):0,
                    gccsTaskData!=null&&gccsTaskData.getLongitude()!=null?Double.parseDouble(gccsTaskData.getLongitude()):0,
                    date,
                    SharedPrefHelper.getInstance().getUserAccount(),
                    "");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private void initBaiduLocation() {
        try {
            //百度地图发布https://lbs.baidu.com/index.php?title=android-privacy
            LocationClient.setAgreePrivacy(true);
            mBaiduLocationClient = new LocationClient(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //通过LocationClientOption设置LocationClient相关参数
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setOpenGps(true); // 打开gps
        option.setCoorType("gcj02"); // 设置坐标类型---mapbox
        option.setScanSpan(1000);
        option.setNeedDeviceDirect(true);
        option.setIsNeedAddress(true); // 可选，设置是否需要地址信息，默认不需要
        option.setIsNeedLocationDescribe(true); // 可选，设置是否需要地址描述
        option.setLocationNotify(false); // 可选，默认false，设置是否当gps有效时按照1S1次频率输出GPS结果
        option.setIgnoreKillProcess(true); // 可选，默认true，定位SDK内部是一个SERVICE，并放到了独立进程，设置是否在stop
        option.setIsNeedLocationDescribe(true); // 可选，默认false，设置是否需要位置语义化结果，可以在BDLocation
        option.setIsNeedLocationPoiList(true); // 可选，默认false，设置是否需要POI结果，可以在BDLocation
        option.SetIgnoreCacheException(false); // 可选，默认false，设置是否收集CRASH信息，默认收集
        option.setIsNeedAltitude(true); // 可选，默认false，设置定位时是否需要海拔信息，默认不需要，除基础定位版本都可用
        //设置locationClientOption
        mBaiduLocationClient.setLocOption(option);
        mBaiduLocationClient.registerLocationListener(new BDAbstractLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
//                LogUtils.e("bdLocation = " + bdLocation.toString());
                //mapView 销毁后不在处理新接收的位置
                if (bdLocation == null || TextUtils.isEmpty(bdLocation.getAddrStr())) {
                    return;
                }
                //百度的坐标转为mabox的坐标
//                if (mapBoxViewListener != null) mapBoxViewListener.onZoomChange((int) zoom);
                //bdLocation.getAdCode() bdLocation.getDirection()  bdLocation.getAddress()   bdLocation.getCity()
                double[] doubles2 = GPSUtils.gcj02towgs84(bdLocation.getLongitude(), bdLocation.getLatitude());
                Point p = Point.fromLngLat(doubles2[0], doubles2[1]);
                locationAddress = new LocationAddress(doubles2[0], doubles2[1],
                        bdLocation.getProvince(), bdLocation.getCity(), bdLocation.getDistrict(),
                        bdLocation.getTown(), bdLocation.getStreet());
                locationAddress.setAddress(bdLocation.getAddrStr());
            }
        });
        //开启地图定位图层
        mBaiduLocationClient.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mBaiduLocationClient!=null){
            mBaiduLocationClient.stop();
        }
        if (sensorManager != null && sensorEventListener != null) {
            sensorManager.unregisterListener(sensorEventListener);
        }
    }

    private int axis_x;
    private int axis_y;

    private void initSensor() {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display dis = wm.getDefaultDisplay();
        int rotation = dis.getRotation();

        axis_x = SensorManager.AXIS_X;
        axis_y = SensorManager.AXIS_Y;
        switch (rotation) {
            case Surface.ROTATION_0:
                break;
            case Surface.ROTATION_90:
                axis_x = SensorManager.AXIS_Y;
                axis_y = SensorManager.AXIS_MINUS_X;
                break;
            case Surface.ROTATION_180:
                axis_x = SensorManager.AXIS_X;
                axis_y = SensorManager.AXIS_MINUS_Y;
                break;
            case Surface.ROTATION_270:
                axis_x = SensorManager.AXIS_MINUS_Y;
                axis_y = SensorManager.AXIS_X;
                break;
            default:
                break;
        }
//        Vibrator mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        // 实例化传感器管理者
        sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        // 初始化加速度传感器
        Sensor mAccelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
//        Sensor.TYPE_ACCELEROMETER：加速度传感器
//        Sensor.TYPE_GYROSCOPE：陀螺仪传感器
//        Sensor.TYPE_LIGHT：光传感器
//        Sensor.TYPE_PROXIMITY：距离传感器
//        Sensor.TYPE_MAGNETIC_FIELD：磁力计传感器
        // 初始化地磁场传感器
        Sensor mMagneticFieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

        Sensor mSensorOrientation = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
        SensorEventListener sensorEventListener = new SensorEventListener() {
            @Override
            public void onSensorChanged(SensorEvent event) {
                float azimuth = event.values[0];//SensorManager.DATA_X
                String direction = getDirection(-azimuth);
//                azimuth = (azimuth + 360) % 360;
                sensorData = new SensorData((int) azimuth, direction, azimuth + "");
            }

            @Override
            public void onAccuracyChanged(Sensor sensor, int accuracy) {

            }
        };
        sensorManager.registerListener(sensorEventListener, mSensorOrientation, SensorManager.SENSOR_DELAY_GAME);
    }

    private String[] directions = {"北", "西北", "西", "西南", "南", "东南", "东", "东北"};

    private String getDirection(float azimuth) {
        azimuth = (azimuth + 360) % 360;
        int index = Math.round(azimuth / 45f) % 8;
        return directions[index];
    }
    private void saveGccsFileToLocal(GccsTaskData data) {
        List<GccsTaskFile> files = mGccsImageAdapter.getData();
        if (files == null || files.size() == 0) return;
        List<GccsTaskFile> fileList = data.getFileList();
        if(fileList==null){
            fileList = new ArrayList<>();
        }
//        List<GccsTaskFile> finalFileList = fileList;
        Stream.of(files).forEach(file -> {
            if (!file.isDefault()&&TextUtils.isEmpty(file.getId())
                    &&TextUtils.isEmpty(file.getLocalId())) {//本地文件
//                GccsTaskFile file = new GccsTaskFile();
                file.setSync(false);
                file.setFileType("0");//照片
                file.setPid(data.getPid());
                file.setTaskId(data.getTaskId());
                file.setDataId(data.getId());
                file.setGccsPType(data.getGccsPType());
                file.setGccsType(data.getGccsType());
                file.setLocalId(IdUtil.fastUUID());
                file.setDeleted(false);
                file.setAngle(sensorData.getAngle() + "");
                file.setAngleDeg(sensorData.getSensorAngle());
                file.setDegree(sensorData.getSensorDegree());
                if(gccsTaskData!=null){
                    file.setLat(gccsTaskData.getLatitude() + "");
                    file.setLon(gccsTaskData.getLongitude() + "");
                    file.setAddress(gccsTaskData.getAddress());
                }else {
                    file.setLat(locationAddress.getLat() + "");
                    file.setLon(locationAddress.getLon() + "");
                    file.setAddress(locationAddress.getAddress());
                }
                taskGccsFileDao.addOrUpdate(file);
//                finalFileList.add(file);
            }
        });
//        data.setFileList(fileList);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==request_code_edit){
            if(resultCode==RESULT_OK){
                getDataDetail();
            }
        }
    }

    private void getDataDetail() {
        showDialog();
        toSubscribeSingleOb(Api.getDefault()
                        .xmGccsInfo(gccsTaskDataId),
                new ProgressObserver(this, false) {
                    @Override
                    protected void _onNext(String result) {
                        try {
                            dismissDialog();
                            Type type = TypeToken.getParameterized(BaseBean.class, GccsTaskData.class).getType();
                            BaseBean<GccsTaskData> bean = new Gson().fromJson(result, type);
                            if (bean != null && bean.getCode() == 200) {
                                gccsTaskData = bean.getData();
                                String qualified ="";
                                if ("1".equals(gccsTaskData.getQualified())){
                                    qualified = "合格";
                                }else if ("0".equals(gccsTaskData.getQualified())){
                                    qualified = "不合格";
                                }
                                String problem ="";
                                if ("0".equals(gccsTaskData.getQualified())){
                                    problem = "可立行立改";
                                }else if ("1".equals(gccsTaskData.getQualified())){
                                    problem = "需长期修改";
                                }

                                tv_task_time.setText("采集时间：" + gccsTaskData.getCreateTime());
                                tv_task_gccs.setText("工程措施：" + (TextUtils.isEmpty(gccsTaskData.getGccsTypeName())?
                                        "":gccsTaskData.getGccsTypeName()));
                                tv_task_adder.setText("采集位置：" + gccsTaskData.getAddress());
                                tv_task_result.setText("抽检结果：" + qualified);
                                tv_task_remake.setText("问题备注：" + gccsTaskData.getRemarks());
                                tv_task_type.setText("问题类型：" + problem);
                                List<GccsTaskFile> taskFiles = taskGccsFileDao.
                                        findByDataId(gccsTaskData.getId());//本地还没上传的
                                if(gccsTaskData.getFileList()==null||gccsTaskData.getFileList().size()==0){
                                    gccsTaskData.setFileList(taskFiles);
                                }else if(taskFiles!=null&&taskFiles.size()>0){//本地有缓存都是离线文件
                                    Stream.of(taskFiles).forEach(item->{
                                        gccsTaskData.getFileList().add(item);
                                    });
                                }
                                if (gccsTaskData.getFileList() != null
                                        && !gccsTaskData.getFileList().isEmpty()){
                                    GccsTaskFile image = gccsTaskData.getFileList().get(0);
                                    currentTaskFile = 0;
//                                    Glide.with(DetailSpotCheckActivity.this).load(path).into(iv_bg);
                                    if(TextUtils.isEmpty(image.getLocalUrl())){
                                        String path = BuildConfig.BASEURL+"gccsFile/preview/image/"+image.getId()
                                                +"?token="+ SharedPrefHelper.getInstance().getToken();
                                        Glide.with(context).load(path).into(iv_bg);
                                    }else {
                                        Glide.with(context).load(image.getLocalUrl()).into(iv_bg);
                                    }
//                                    if (gccsTaskData.getFileList().size() > 1){
//                                        ll_flag.setVisibility(View.VISIBLE);
//                                        mGccsImageAdapter.setSelectedPosition(0);
//                                        mGccsImageAdapter.setNewData(gccsTaskData.getFileList());
//                                    }
//                                    ll_flag.setVisibility(View.VISIBLE);
                                    mImageList.clear();
                                    mImageList.addAll(gccsTaskData.getFileList());
                                    mGccsImageAdapter.setComplaintData(mImageList);
                                    mGccsImageAdapter.setSelectedPosition(1);
                                }else {
                                    mImageList.clear();
                                    mGccsImageAdapter.setComplaintData(mImageList);
                                    mGccsImageAdapter.setSelectedPosition(1);
                                }
                            } else {
                                ToastUtils.toast(bean != null ? bean.getMsg() : "数据解析异常");
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            ToastUtils.toast("数据解析异常");
                        }
                    }

                    @Override
                    protected void _onError(String result) {
                        dismissDialog();
                    }
                });
    }
}
